package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.Workorder;
import com.qf.mapper.ProjectMapper;
import com.qf.mapper.WorkorderMapper;
import com.qf.service.WorkorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 10537
 * @version V1.0
 * @Date 2021/10/5 16:37
 */
@Service
public class WorkorderServiceImpl implements WorkorderService {

    @Autowired
    private WorkorderMapper workorderMapper;

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void add(Workorder workorder) {
        int i = workorderMapper.insert(workorder);
        if (i!=1){
            System.out.println("添加工单信息失败");
            throw new RuntimeException("添加工单信息失败");
        }
    }

    @Override
    public PageInfo<Workorder> findByPage(Integer page, Integer rows,Integer projectId) {
        PageHelper.startPage(page,rows);
        List<Workorder> workorders = workorderMapper.selectByProjectId(projectId);
        PageInfo<Workorder> pageInfo=new PageInfo<>(workorders);
        return pageInfo;
    }
}
